<template>
  <view class="goods-item" @click="goToDetail(goods.goods_id)">
    <!-- 左边 -->
    <view class="goods-item-left">
      <slot name="radio" />
      <image
        :src="goods.goods_small_logo || defaultPic"
        mode="scaleToFill"
        class="goods-pic"
      />
    </view>
    <!-- 右边 -->
    <view class="goods-item-right">
      <text class="goods-name">{{ goods.goods_name }}</text>
      <view class="price-number">
        <text class="goods-price">￥{{ goods.goods_price | toFixed }}</text>
        <slot name="number" />
      </view>
    </view>
  </view>
</template>

<script>
export default {
  props: {
    goods: {
      type: Object,
      default: () => {},
    },
  },
  data() {
    return {
      // 默认的空图片
      // defaultPic:
      // 'https://img3.doubanio.com/f/movie/8dd0c794499fe925ae2ae89ee30cd225750457b4/pics/movie/celebrity-default-medium.png' // 公司里一般是本地的

      // defaultPic: '../../static/logo.png' // 发现uniapp中支持
      defaultPic: require("../../static/logo.png"),
    };
  },
  methods: {
    // 跳转到详情页面
    goToDetail(goods_id) {
      // subpkg记得加个/代表拼接基地址
      uni.navigateTo({
        url: `/subpkg/goods_detail/index?goods_id=${goods_id}`,
      });
    },
  },
  filters: {
    toFixed(val) {
      return val.toFixed(2);
    },
  },
};
</script>

<style lang="scss" scoped>
.goods-item {
  display: flex;
  padding: 10px 5px;
  border-bottom: 1px solid #f0f0f0;

  .goods-item-left {
    margin-right: 5px;
    display: flex;
    align-items: center;

    .goods-pic {
      width: 100px;
      height: 100px;
      display: block;
    }
  }

  .goods-item-right {
    display: flex;
    flex-direction: column;
    justify-content: space-between;

    .goods-name {
      font-size: 13px;
    }

    .goods-price {
      font-size: 16px;
      color: #c00000;
    }
    .price-number {
      display: flex;
      align-items: center;
      justify-content: space-between;
    }
  }
}
</style>